var gotoSearch,gotoUpgradeDetail,logType;
require(['grid', 'topBar', 'layout', 'date'], function () {
	$('#top').topBar({
		left: [
			{
				type: 'filter-more',
				dateType:'custom',
				search: function () {
					search();
				},
				item: [
					{
						text: '时间快捷',
						name1: 'beginTime',
						name2: 'endTime',
						type: 'dateLine'
					}, {
						text: '按条件汇总',
						name: 'logType',
						type: 'item-select',
						data: [
							{text: '全部', value: ''},
							{text: '核心板应用', value: 'ULOG0001'},
							{text: '主板应用', value: 'ULOG0007'},
							{text: 'CAN数据相关配置文件', value: 'ULOG0018'},
							{text: '线路文件', value: 'ULOG0002'},
							{text: '通讯参数', value: 'ULOG0011'},
							{text: '外设参数', value: 'ULOG0012'},
							{text: '唯一参数', value: 'ULOG0013'},
							{text: '行为参数', value: 'ULOG0014'},
							{text: '线路参数', value: 'ULOG0015'},
							{text: '发动机参数', value: 'ULOG0016'},
							{text: '电机参数', value: 'ULOG0017'}
						]
					}
				]
			}
		]
	});

	//grid初始化
	function gridInit() {
		$('#grid').grid({
			url: "/upgrade/searchUpgradeLog.htm",
			multiselect: true,
			colModel:[
				{name: "lineName", label: "运营线路"},
				{name: "licPltNo", label: "车牌号"},
				{name: "eqmtCd", label: "设备编码"},
				{name: "upgradeBeginTime", label: "升级开始时间"},
				{name: "upgradeEndTime", label: "升级结束时间"},
				{name: "runTime", label: "升级时长"},
				{name: "vrsnName", label: "升级版本名称"},
				{name: "upgradeSt", label: "升级状态",dict:"UPST0000"},
				{name: "stMsg", label: "状态消息",dict:"UPSM0000"},
				{name: "upgradeUser", label: "升级用户"}
			],
			showPaper: true
		});
	}

	function search() {
		passParams = null;
		var $postData = $("#top").parent().getValues();
		// 左侧树tab选中的类型
		var type = commonFun.getLeftTreeCurrentTreeType();
		var orgIds = commonFun.getLeftTreeCheckedNodes(type);
		if (!orgIds) {
			$.messager.alert("提示", "请选择查询车辆/机构/驾驶员！", "info");
		} else {
			$postData.type = type;
			$postData.orgIds = orgIds.toString();
			$postData.appUpgrade ="";
			$postData.logId="";
			$('#grid').grid('setGridParam', {
				datatype: "json",
				postData: $postData
			}).trigger("reloadGrid");
		};
	};

	function Appendzero (obj) {
		if (obj < 10) {
			return "0" + obj;
		}else{
			return obj;
		}
	}

	gotoSearch = function (data) {
		// if (data.lineIds) {
		// 	//切换成线路
		// 	commonFun.showLeftTree(commonFun.lineTree);
		// 	//勾选并展开节点
		// 	commonFun.setCheckedNodes(data.lineIds);
		// }
		// else if (data.carIds) {
		// 	//切换成车辆
		// 	commonFun.showLeftTree(commonFun.carTree);
		// 	//勾选并展开节点
		// 	commonFun.setCheckedNodes(data.carIds);
		// }
		var now = new Date ();
		var year = now.getFullYear ();//获取四位数年数
		var month = now.getMonth () + 1;
		var date = now.getDate ();
		var weeknum = now.getDay ();
		var str = year + "-" + Appendzero (month) + "-" + Appendzero (date);
		$('.topBar').find('[name=beginTime]').val(str);
		$('.topBar').find('[name=endTime]').val(str);
		data.beginTime=str;
		data.endTime=str;
		if(data.appUpgrade=="5") {
			logType="ULOG0011";
		}else if(data.appUpgrade=="6"){
			logType="ULOG0012";
		}else if(data.appUpgrade=="8"){
			logType="ULOG0014";
		}else if(data.appUpgrade=="9"){
			logType="ULOG0015";
		}else if(data.appUpgrade=="10"){
			logType="ULOG0016";
		}else if(data.appUpgrade=="11"){
			logType="ULOG0017";
		}else if(data.appUpgrade=="7"){
			logType="ULOG0013";
		}else if(data.appUpgrade=="1"){
			logType="ULOG0001";
		}else if(data.appUpgrade=="2"){
			logType="ULOG0002";
		}else if(data.appUpgrade=="3"){
			logType="ULOG0007";
		}else if(data.appUpgrade=="12"){
			logType="ULOG0018";
		}
		$("a[data-val='"+logType+"']",".more-area").click();
		$('#grid').grid('setGridParam', {
			datatype: "json",
			postData: data
		}).trigger("reloadGrid");
	}

	gotoUpgradeDetail = function (params) {
		//切换成车辆
		commonFun.showLeftTree(commonFun.carTree);
		//勾选并展开节点
		commonFun.setCheckedNodes(params.carIds);
		$('.topBar').find('[name=beginTime]').val();
		$('.topBar').find('[name=endTime]').val();
        $("a[data-val='"+params.logType+"']",".more-area").click();
		if(params.logId){
			$('#grid').grid('setGridParam', {
				datatype: "json",
				postData: {"logId":params.logId}
			}).trigger("reloadGrid");
		}
	}

	$('body').layout();
	//初始化grid
	gridInit();
});
